import 'package:flutter/material.dart';
import 'package:flutter_eve_plugin/components/health/title_view.dart';
import 'package:flutter_eve_plugin/model/health/user_body_property.dart';
import 'package:flutter_eve_plugin/store/main.dart';
import 'package:flutter_eve_plugin/store_vm/app_vm.dart';
import 'package:flutter_eve_plugin/utils/screen_util.dart';
import 'package:flutter_redux/flutter_redux.dart';

class TodayDynamicWidget extends StatelessWidget {
  const TodayDynamicWidget({
    Key key,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return StoreConnector<AppState, AppStateViewModel>(
        converter: (store) => AppStateViewModel(state: store.state),
        builder: (context, vm) {
          List<UserBodyDataInfo> list =
              vm.state.headlthState.userBodyModel.data;
          if (list == null || list.isEmpty) {
            return Container();
          }
          var infoList1 = list?.where((item) {
            return item.name == '卡路里摄入';
          })?.toList();
          var infoList2 = list?.where((item) {
            return item.name == '卡路里消耗';
          })?.toList();
          var infoList3 = list?.where((item) {
            return item.name == '营养';
          })?.toList();
          return Column(
            mainAxisAlignment: MainAxisAlignment.start,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: <Widget>[
              HealthTitleViewWidget(
                title: '今日动态',
              ),
              SizedBox(
                height: setRatio(25),
              ),
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceAround,
                crossAxisAlignment: CrossAxisAlignment.center,
                children: children(infoList1, infoList2, infoList3),
              )
            ],
          );
        });
  }

  List<Widget> children(List<UserBodyDataInfo> infoList1,
      List<UserBodyDataInfo> infoList2, List<UserBodyDataInfo> infoList3) {
    if (infoList1 == null ||
        infoList2 == null ||
        infoList3 == null ||
        infoList1.isEmpty ||
        infoList2.isEmpty ||
        infoList3.isEmpty) {
      return [Container()];
    }
    return <Widget>[
      Column(
        mainAxisAlignment: MainAxisAlignment.center,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: <Widget>[
          Text(
            '${infoList1?.first?.value ?? ""}',
            style: TextStyle(
                color: Color.fromRGBO(121, 117, 255, 1),
                fontSize: setTextSp(15),
                fontWeight: FontWeight.w600),
          ),
          SizedBox(
            height: setRatio(11),
          ),
          Text(
            infoList1?.first?.name ?? '',
            style: TextStyle(
                color: Color.fromRGBO(153, 153, 153, 1),
                fontSize: setTextSp(11),
                fontWeight: FontWeight.w500),
          )
        ],
      ),
      Container(
        width: setRatio(1),
        height: setRatio(19),
        color: Color.fromRGBO(235, 235, 235, 1),
      ),
      Column(
        mainAxisAlignment: MainAxisAlignment.center,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: <Widget>[
          Text(
            '${infoList2?.first?.value ?? ""}',
            style: TextStyle(
                color: Color.fromRGBO(121, 117, 255, 1),
                fontSize: setTextSp(15),
                fontWeight: FontWeight.w600),
          ),
          SizedBox(
            height: setRatio(11),
          ),
          Text(
            infoList2?.first?.name ?? '',
            style: TextStyle(
                color: Color.fromRGBO(153, 153, 153, 1),
                fontSize: setTextSp(11),
                fontWeight: FontWeight.w500),
          )
        ],
      ),
      Container(
        width: setRatio(1),
        height: setRatio(19),
        color: Color.fromRGBO(235, 235, 235, 1),
      ),
      Column(
        mainAxisAlignment: MainAxisAlignment.center,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: <Widget>[
          Text(
            '${infoList3?.first?.value ?? ""}',
            style: TextStyle(
                color: Color.fromRGBO(121, 117, 255, 1),
                fontSize: setTextSp(15),
                fontWeight: FontWeight.w600),
          ),
          SizedBox(
            height: setRatio(11),
          ),
          Text(
            '获取${infoList3?.first?.name ?? ""}',
            style: TextStyle(
                color: Color.fromRGBO(153, 153, 153, 1),
                fontSize: setTextSp(11),
                fontWeight: FontWeight.w500),
          )
        ],
      )
    ];
  }
}
